/*
https://leetcode-cn.com/problems/uncrossed-lines/solution/bu-xiang-jiao-de-xian-by-leetcode-soluti-6tqz/
 */
public class Solution1035 {
    public int maxUncrossedLines(int[] nums1, int[] nums2) {
        int n=nums1.length,m=nums2.length;
        int[][] f=new int[n+1][m+1];
        for (int i=1;i<=n;i++){
            for (int j=1;j<=m;j++){
                if (nums1[i-1]==nums2[j-1]){
                    f[i][j]=f[i-1][j-1]+1;
                }else{
                    f[i][j]=Math.max(f[i][j-1],f[i-1][j]);
                }
            }
        }
        return f[n][m];
    }

    public static void main(String[] args) {
        System.out.println(new Solution1035().maxUncrossedLines(new int[]{2,5,1,2,5},new int[]{10,5,2,1,5,2}));
    }
}
